/*
 * RadioButton.cpp
 *
 *  Created on: 2010-12-15
 *      Author: wenjian
 */

#include "RadioButton.h"

namespace S {

  RadioButton::RadioButton(real x, real y, bool checked)
    :checkedFlag(checked) {
    pen = new Gdiplus::Pen(Gdiplus::Color(1, 1, 1));
    brush = new Gdiplus::SolidBrush(Gdiplus::Color(1, 1, 1));

    setCoordinate(x, y);
    setWidth(25);
    setHeight(25);
    createBoundRect();
  }

  RadioButton::~RadioButton() {
    delete buttonImage;
    delete checkedButtonImage;
    delete pen;
    delete brush;
  }


  /**
   * 画此元素
   */
  void RadioButton::draw(Gdiplus::Graphics* g) {
    Gdiplus::RectF r;
    g->DrawEllipse(pen, *getBoundRect(&r, -3.0f));
    getBoundRect(&r, -8);
    if(checkedFlag){
      g->DrawEllipse(pen, r);
      g->FillEllipse(brush, r);
    }else{
      g->DrawEllipse(pen, r);
    }
    if (mouseIsHovering()) {
      g->DrawRectangle(pen, *getBoundRect(&r, -1.0f));
    }
    setModified(false);
    setRedraw(false);
  }

    /**
     * 当鼠标在按钮上移动时
     */
    void RadioButton::mouseMoveEvent(const MouseEvent* e) {
//      if (!isHovering) {
//        isHovering = true;
//        setModified(true);
//      }
      setModified(true);
    }
    /**
     * 当鼠标在按钮上移出时
     */
    void RadioButton::mouseLeaveEvent(const MouseEvent* e) {
//      isHovering = false;
      setModified(true);
    }

    /**
     * 当鼠标在元素上按下按键时
     */
    void RadioButton::mousePressEvent(const MouseEvent* e) {
      setChecked(true);
    }

}
